// Nested callback process cache use is not lag-safe with regard to HOLDOFF_TTL since
// process cached values are more lagged than persistent ones as they are not purged.
if ( $pCache && $this->callbackDepth == 0 ) {
- $cached = $pCache->get( $this->getProcessCacheKey( $key, $version ), INF, false );
+ $cached = $pCache->get( $this->getProcessCacheKey( $key, $version ), $pcTTL, false );
if ( $cached !== false ) {
return $cached;
}
if ( !isset( $this->processCaches[$group] ) ) {
list( , $size ) = explode( ':', $group );
$this->processCaches[$group] = new MapCacheLRU( (int)$size );
+ if ( $this->wallClockOverride !== null ) {
+ $this->processCaches[$group]->setMockTime( $this->wallClockOverride );
+ }
}
return $this->processCaches[$group];
public function setMockTime( &$time ) {
$this->wallClockOverride =& $time;
$this->cache->setMockTime( $time );
+ foreach ( $this->processCaches as $pCache ) {
+ $pCache->setMockTime( $time );
+ }
}
}
$this->assertFalse( $this->cache->get( $key ), "Stale set() value ignored" );
}
+ /**
+ * @covers WANObjectCache::getWithSetCallback
+ */
+ public function testProcessCacheTTL() {
+ $cache = $this->cache;
+ $mockWallClock = 1549343530.2053;
+ $cache->setMockTime( $mockWallClock );
+
+ $key = "mykey-" . wfRandomString();
+
+ $hits = 0;
+ $callback = function ( $oldValue, &$ttl, &$setOpts ) use ( &$hits ) {
+ ++$hits;
+ return 42;
+ };
+
+ $cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
+ $cache->delete( $key, $cache::HOLDOFF_NONE ); // clear persistent cache
+ $cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
+ $this->assertEquals( 1, $hits, "Value process cached" );
+
+ $mockWallClock += 6;
+ $cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
+ $this->assertEquals( 2, $hits, "Value expired in process cache" );
+ }
+
/**
* @covers WANObjectCache::getWithSetCallback
*/